/*
package filters;

import transaction.TransactionManager;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebFilter("*.action")
public class OpenSessionInViewFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        TransactionManager transactionManager =  TransactionManager.getInstance();
        HttpServletRequest request = (HttpServletRequest)servletRequest ;
        HttpServletResponse response = (HttpServletResponse)servletResponse;

        try {
            //1.开启事务
            transactionManager.start();
            System.out.println("开启事务。。。。。。。。。。");
            filterChain.doFilter(request,response);
            //2.提交事务
            transactionManager.commit();
            System.out.println("提交事务。。。。。。。。。。");

        } catch (SQLException e) {
            //3.回滚事务
            try {
                transactionManager.rollback();
                System.out.println("事务回滚了。。。。。。。。");
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        }

    }

    @Override
    public void destroy() {

    }
}
*/
